package cn.fu.ssh.service.impl;

import java.util.List;

import cn.fu.ssh.dao.ILeaveBillDao;
import cn.fu.ssh.domain.Employee;
import cn.fu.ssh.domain.LeaveBill;
import cn.fu.ssh.service.ILeaveBillService;
import cn.fu.ssh.utils.SessionContext;

public class LeaveBillServiceImpl implements ILeaveBillService {

	private ILeaveBillDao leaveBillDao;

	public void setLeaveBillDao(ILeaveBillDao leaveBillDao) {
		this.leaveBillDao = leaveBillDao;
	}

	/**查询所有的请假单列表*/
	public List<LeaveBill> findLeaveBillList() {
		List<LeaveBill> list = leaveBillDao.findLeaveBillList();
		return list;
	}

	/**保存/更新请假单*/
	public void saveLeaveBill(LeaveBill leaveBill) {
		//获取请假申请单的ID，判断执行的是新增的操作还是修改的操作
		Long id = leaveBill.getId();
		//执行新增
		if(id==null){
			//获取页面的表单值，从Session中获取当前用户的对象，建立多对一的关联关系，直接执行保存
			Employee employee = SessionContext.get();
			//组织PO对象
			//leaveBill.setState(0);//设置状态，0表示初始状态
			leaveBill.setUser(employee);//建立多对一的关联关系
			leaveBillDao.save(leaveBill);
		}
		//执行编辑
		else{
			leaveBillDao.update(leaveBill);
		}
		
	}

	/**使用主键ID，查询请假申请单的对象*/
	public LeaveBill findLeaveBillByID(Long id) {
		LeaveBill bill = leaveBillDao.findLeaveBillByID(id);
		return bill;
	}
	
	/**使用ID，删除请假单*/
	public void deleteLeaveBillByID(Long id) {
		leaveBillDao.deleteLeaveBillByID(id);
	}
}
